package com.sunlee.app.api.controller;

import com.sunlee.app.api.annotation.Login;
import com.sunlee.common.core.entity.Result;
import com.sunlee.common.service.entity.CommonUserEntity;
import com.sunlee.app.api.context.UserContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 测试接口
 *
 * @author sunlee
 */
@RestController
@RequestMapping("/api")
public class ApiTestController {

    @Login
    @GetMapping("userInfo")
    public Result<CommonUserEntity> userInfo() {
        return Result.ok(UserContext.getUserInfo());
    }

    @Login(required = false)
    @GetMapping("userInfoF")
    public Result<CommonUserEntity> userInfoF() {
        return Result.ok(UserContext.getUserInfo());
    }

    @Login
    @GetMapping("userId")
    public Result<Long> userInfo(@ApiIgnore @RequestAttribute("userId") Long userId) {
        return Result.ok(userId);
    }

    @GetMapping("notToken")
    public Result<String> notToken() {
        return Result.ok("无需token也能访问。。。");
    }

}